package com.arges.web.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.springframework.stereotype.Repository;

import com.arges.web.domain.pojo.Pat;

/**
 * 患者基本信息dao
 *
 * @author zxj
 */
@Repository
public class PatDao extends GenericDao<Pat, Long>
{

	public Pat getPatByMrn(String mrn)
	{
		String hql = "from Pat p where p.mrn=?";
		return (Pat) getSession().createQuery(hql).setParameter(0, mrn).uniqueResult();
	}

	public void deletePatByIds(Long[] deleteId)
	{
		StringBuffer hql = new StringBuffer();
		hql.append("delete from Pat where id in (");
		for (int i = 0; i < deleteId.length; i++)
		{
			hql.append(deleteId[i] + ",");
		}
		hql.deleteCharAt(hql.length() - 1).append(")");
		getSession().createQuery(hql.toString()).executeUpdate();
	}

	public Pat getLastPat()
	{
		String hql = "from Pat p order by p.id desc ";
		return (Pat) getSession().createQuery(hql).setFirstResult(0).setMaxResults(1).uniqueResult();
	}

	@SuppressWarnings("unchecked")
	public List<Pat> findByDate(Class<Pat> class1, Criterion condiition)
	{
		Criteria criteria = getSession().createCriteria(class1);
		if (null != condiition)
		{
			criteria.add(condiition);
		}

		List<Pat> result = criteria.list();
		return result;
	}
}
